package com.cetcs.kmga.hbase.index;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;


/**
 * Hbase数据库连接池
 *
 * @author xutao
 * @version V1.0 创建时间：2017-08-30 11:27
 *          Copyright 2017 by CETC
 */
public class HBasePool {

    private final static Logger LOGGER = LoggerFactory.getLogger(HBasePool.class);

    private static Configuration configuration;

    private static Connection conn;



    static {
        configuration = HBaseConfiguration.create();
        configuration.addResource(new Path("hbase-site.xml"));
        configuration.addResource(new Path("core-site.xml"));
    }

    private static HBasePool instance = null;

    public static HBasePool getInstance() {
        if (instance == null) {
            instance = new HBasePool();
        }
        return instance;
    }

    public Connection getConnection() {
        try {
            if (conn == null) {
                conn = ConnectionFactory.createConnection(configuration);
            }
        } catch (IOException e) {
            LOGGER.error(" get conn is error,error msg：" + e.getMessage(), e);
        }
        return conn;

    }


}
